ActiveAdmin.register Overview do
  menu label: '概况', parent: '数据统计'


  filter :company, label: '集团'
  controller do
    def index
      @company = params[:q][:company_contains] rescue ""
      index! do |format|
        format.html {render 'admin/overviews/index', layout: 'active_admin'}
      end
    end

    def data
      render json: {
          total: Overview.ransack(company_contains: params[:company]).result.count,
          rows: Overview.ransack(company_contains: params[:company]).result.map {|r|
            {
                report_date: r.report_date,
                company: r.company,
                all_stores: r.all_stores,
                free_stores: r.free_stores,
                tuition_stores: r.tuition_stores,
                all_course: r.all_course,
                all_place: r.all_place,
                free_course: r.free_course,
                free_place: r.free_place,
                tuition_course: r.tuition_course,
                tuition_place: r.tuition_place,
                all_appointed: r.all_appointed,
                free_appointed: r.free_appointed,
                tuition_appointed: r.tuition_appointed,
                credit: r.credit,
                pay_credit: r.pay_credit,
                actually_credit: r.actually_credit,
                pay_member: r.pay_member
            }
          }
      }
    end
  end
end
